package com.baor.service.impl;

import com.baor.dao.CouponDao;
import com.baor.domain.AdminVo;
import com.baor.domain.CouponVo;
import com.baor.service.CouponService;
import com.baor.utils.AjaxResult;
import com.baor.utils.DateUtil;
import com.ctc.wstx.util.DataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.unit.DataUnit;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
@Service
public class CouponServiceImpl implements CouponService {
    @Autowired
    private CouponDao couponDao;
    @Override
    public AjaxResult<?> list(Map<String, Object> params) {
        if(params.containsKey("pageIndex")&&params.containsKey("pageSize")){
            int pageIndex= (int) params.get("pageIndex");
            int pageSize = (int) params.get("pageSize");
            params.put("pageIndex",(pageIndex - 1) * pageSize);
            List<CouponVo> adminVoList = this.couponDao.list(params);
            Map<String,Object> res = this.couponDao.findPageCount(params);
            res.put("adminList",adminVoList);
            return AjaxResult.success(res);
        }else{
            return AjaxResult.error();
        }
    }

    @Override
    public AjaxResult<?> insert(CouponVo couponVo) {
        int row = this.couponDao.insert(couponVo);
        if(row>0){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }

    @Override
    public AjaxResult<?> delete(Map<String,Object> params) {
        int couponId = (int) params.get("couponId");
        int row = this.couponDao.deleteById(couponId);
        if(row>0){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }

    @Override
    public AjaxResult<?> update(CouponVo couponVo) {
        int row = this.couponDao.updateById(couponVo);
        if(row>0){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }

    @Override
    public AjaxResult<?> separateList() {
        return AjaxResult.success(this.couponDao.separateList());
    }

    @Override
    public AjaxResult<?> goodsList() {
        return AjaxResult.success(this.couponDao.goodsList());
    }
}
